﻿using AiXiu.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AiXiu.DAL
{
    public class UserManager
    {
        AiXiuDbContext dbContext = new AiXiuDbContext();
        /// <summary>
        /// 查询
        /// </summary>
        /// <returns></returns>
        public List<TBUsers> getList()
        {
            
            var list = dbContext.TBUsers.ToList();
            return list;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int Add(TBUsers user)
        {
            dbContext.TBUsers.Add(user);
            return dbContext.SaveChanges();
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="id"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public int Update(int id,string name) 
        {
            var list = dbContext.TBUsers.Where(t => t.Id == id).FirstOrDefault();
            list.NickName = name;
            return dbContext.SaveChanges();
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delete(int id) 
        {
            var list = dbContext.TBUsers.Where(t => t.Id == id).FirstOrDefault();
            dbContext.TBUsers.Remove(list);
            return dbContext.SaveChanges();
        }
    }
}
